Skip to content

feat(pi): TokenPilot adapter for pi - #98

Merged
Xubqpanda merged 3 commits into
zjunlp:mainfrom
boxabirds:claude/upstream-7-pi-adapter
Oct 3, 2026
Merged

Xubqpanda merged 3 commits into
zjunlp:mainfrom
boxabirds:claude/upstream-7-pi-adapter

Conversation

@boxabirds

@boxabirds boxabirds commented Oct 2, 2026 •

Copy link
Copy Markdown

Summary

Closes #97. Adds TokenPilot support for pi (@earendil-works/pi-coding-agent), verified on 0.87.1.

It builds on the shared code merged in #96. 38 files and about 2,900 lines, mostly the adapter and its tests.

Measured benefit

The test used llama-server with Qwen3-1.7B and a 32k context window, running the same 4-turn coding session with the adapter off and on, each from a fresh model load. The session runs a build, reads and counts a JSON file, writes a file, then recalls the build's last line.

Adapter off Adapter on
Prompt tokens processed 37,371 4,985 (−87%)
Wall time 834 s 69 s
pi had to compact the conversation yes, once no

With the adapter on, the model recovered the trimmed build output with memory_fault_recover in the last turn. lightrsi pi doctor reported healthy after the run.

How it plugs in

pi has an in-process extension API, so no proxy is needed and no pi-owned config file is changed.

TokenPilot feature pi hook
Stable prefix before_agent_start system-prompt sections, so pi appends a section change instead of replacing the prompt
Reduction the request-local context hook
Recovery a native memory_fault_recover tool with the shared MCP tool's name, description and schema, since pi has no MCP
Eviction (opt-in, off by default) native context_edit entries at turn_end, which apply before pi's own compaction

Install is reversible. It writes one extension loader file, with a backup of anything already there, and a tokenpilot.json that never contains credentials. Uninstall removes only what install added. The adapter is also registered in the shared CLI as lightrsi pi status|report|doctor|visual|mode|….

What's in the 3 commits

Area Lines
pi adapter (components/adapters/pi) ~1,320
Tests ~1,080
Docs (README, design note, HOSTS.md, website page) ~440
CLI registration ~60
Lockfile and CI step ~45

The adapter reuses the shared code from #96 for config, reduction, eviction and the repeat-read rule from #92, so it adds no new shared code.

Known limits

  • mode aggressive isn't exposed, as on Claude Code and OpenCode.
  • There are no in-host slash commands; use the shared CLI instead.
  • The Context Cleaner isn't integrated yet.

Tests

  • pi adapter: 86 tests. They cover the runtime hooks, the message codec, install and uninstall, doctor and registration.
  • CLI: 116 tests. Every in-process host case now runs for both pi and OpenCode.
  • pnpm build, pnpm typecheck and check:boundaries pass, and every suite CI runs passes.

Prepared with help from Claude Code; the commits are marked Co-Authored-By: Claude.

claude added 3 commits October 2, 2026 12:09
Adds an in-process extension for the pi coding agent
(`@earendil-works/pi-coding-agent`, verified on 0.87.1) in
`components/adapters/pi`, built on the shared host glue from the OpenCode
adapter (`components/adapters/shared/canonical`). Refs zjunlp#97.

- Stabilizer: `before_agent_start` system-prompt sections, so pi appends a
  section delta instead of replacing the prompt.
- Reduction: request-time in the `context` hook, through the shared
  `@lightrsi/reduction` pipeline over a canonical envelope.
- Recovery: a native `memory_fault_recover` tool with the shared MCP tool's
  name, description and schema (pi has no MCP).
- Eviction (opt-in, needs taskStateEstimator settings): the shared
  canonical-surface cycle, applied as native `context_edit` entries at
  `turn_end`, before pi's own threshold compaction.
- Repeat-read rule: the shared disclosed-read memo, as in zjunlp#92 and the
  OpenCode adapter, saved per session so `pi -p` / `--continue` restarts keep
  it.
- Reversible install with backups; never writes credentials; every hook fails
  open and logs to `<stateDir>/tokenpilot/adapter.log`.

Tests: 86 in the package (runtime, codec, install/doctor, registration). The
shared glue is already covered by the OpenCode package's suites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
`lightrsi pi status|report|doctor|visual|mode|stabilizer|reduction|eviction`
through the existing in-process host bridge, so pi gets the same command
surface as OpenCode. TOKENPILOT_PI_CONFIG selects a non-default config file.

Tests: tests/in-process-hosts.test.ts now runs every case for both pi and
OpenCode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
- components/adapters/pi/README.md is in the adapter commit; this adds the
  design note (docs/adapters/pi-design.md), the HOSTS.md and adapters README
  rows, the website host page and compatibility matrix, and the sidebar link.
- CI runs the pi adapter suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
@Xubqpanda
Xubqpanda merged commit 33c8ebf into zjunlp:main Oct 3, 2026
2 checks passed
@Xubqpanda

Copy link
Copy Markdown
Collaborator

Thanks @boxabirds — merged! Great to see pi land as our first in-process, proxy-free adapter, and the measured result (37,371 → 4,985 prompt tokens, 834 s → 69 s) is a strong signal. Also nice that the adapter reuses the shared code from #96 rather than adding new shared logic. Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: TokenPilot support for pi

3 participants